<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8"/>
    <title>Title</title>
    <meta name="description" content="Static &amp; Dynamic Tables" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/bootstrap-responsive.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="assets/css/xcConfirm.css"/>
    <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
    <link rel="stylesheet" href="assets/css/ace.min.css" />
    <link rel="stylesheet" href="assets/css/ace-responsive.min.css" />
    <link rel="stylesheet" href="assets/css/ace-skins.min.css" />
    <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
</head>
<body>
<div class="row-fluid">
    <div class="span12">
        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>id</th>
                <th>名称</th>
                <th>组名</th>
                <th>任务类型</th>
                <th class="hidden-480">状态</th>
                <th class="hidden-480">cron表达式</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody>
            <tr th:each="config : ${configs}">
                <td th:text="${config.id}">id</td>
                <td th:text="${config.jobName}">jobName</td>
                <td th:text="${config.jobGroup}">jobGroup</td>
                <td th:text="${config.jobType}">jobType</td>
                <td th:if="${config.status == '启用'}"><span class="label label-success">启用</span></td>
                <td th:if="${config.status == '停用'}"><span class="label label-danger">停用</span></td>
                <td th:id="${config.id}" class="hidden-480" th:text="${config.cron}">cron</td>
                <td>
                    <div class="hidden-phone visible-desktop btn-group">
                        <button class="btn btn-mini btn-success"
                                th:if="${config.status == '停用'}"
                                th:onclick="'javascript:changeJobStatus(\''+${config.id}+'\',\'0\');'">
                             <i class="icon-ok bigger-120">启用</i>
                        </button>

                        <button class="btn btn-mini btn-danger"
                                th:if="${config.status == '启用'}"
                                th:onclick="'javascript:changeJobStatus(\''+${config.id}+'\',\'1\');'">
                            <i class="icon-bolt bigger-120">停用</i>
                        </button>

                        <button class="btn btn-mini btn-info"
                                th:onclick="'javascript:updateCron(\''+${config.id}+'\');'">
                            <i class="icon-edit bigger-120"></i>
                        </button>

                        <button class="btn btn-mini btn-success"
                                th:onclick="'javascript:nowRun(\''+${config.id}+'\');'">
                            <i class="icon-ok bigger-120">立即执行</i>
                        </button>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
    </div><!--/span-->

</div><!--/row-->
<script src="/jquery-1.9.1.min.js"></script>
<script src="/xcConfirm.js"></script>
<script>
    function changeJobStatus(id,status) {
        $.ajax({
            type : "POST",
            async : false,
            dataType : "JSON",
            cache : false,
            url : "/updateStatus",
            data : {
                id : id,
                status: status
            },
            success : function(data) {
                if (data.result) {
                    location.reload();
                } else {
                    alert(data.msg);
                }

            }
        });
    }
    function updateCron(id) {
        var txt=  "请输入cron表达式";
        window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.input,{
            onOk:function(v){
                $.ajax({
                    type : "POST",
                    async : false,
                    dataType : "JSON",
                    cache : false,
                    url : "/updateQuartz",
                    data : {
                        id : id,
                        cron: v
                    },
                    success : function(data) {
                        if (data.result) {
                            location.reload();
                        } else {
                            alert(data.msg);
                        }

                    }
                });
            }
        });
    }
    function nowRun(id){
        $.ajax({
            type : "POST",
            async : false,
            dataType : "JSON",
            cache : false,
            url : "/nowRun",
            data : {
                id : id
            },
            success : function(data) {
                if (data.result) {
                    location.reload();
                } else {
                    alert(data.msg);
                }

            }
        });
    }
</script>
</body>
</html>